<?php

namespace Frieza\Modules\Position\Controllers;

use Doraemon\tools\ImgUrl;
use Encore\Admin\Grid;
use Encore\Admin\Widgets\Form;
use Illuminate\Http\Request;


class HomeChannelController extends BaseController
{
    use BaseTrait;

    public function extendList(Grid $grid)
    {
        $grid->column('pos', '位置');
        $grid->column('title', '标题');
        $grid->column('icon_url', '图标')->image('', 50, 50);
        $grid->column('ext_icon_url', '额外图标')->image();
    }

    public function extendSaveBaseInfo(Request $request): array
    {
        $title = $request->input("title", "");
        $icon_id = $request->input("icon_id", "");
        $small_icon_id = $request->input("small_icon_id", "");
        return ['pic_id' => json_encode(compact('title', 'icon_id', 'small_icon_id'))];
    }

    public function beforeTitleForm(Form $form)
    {
        $seed = range(1, 20);
        $form->select('base.pos', '位置')->options(array_combine($seed, $seed));
        $form->text('title', '标题');
        $form->imgUpload('icon_id', '图标', false, ['imgType' => ImgUrl::APPTYPE_OP, 'imgSize' => ImgUrl::IMAGE_SIZE_OP_ORI]);
        $form->imgUpload('small_icon_id', '额外图标', false, ['imgType' => ImgUrl::APPTYPE_OP, 'imgSize' => ImgUrl::IMAGE_SIZE_OP_ORI]);
    }

}
